package thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class THreadPoolClose {
    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(3,6,10, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                new ThreadPoolExecutor.AbortPolicy());
        for (int i = 0; i < 6; i++) {
            pool.submit(() ->{
                while (true){
                    System.out.println(Thread.currentThread().getName() + "is working...");
                    Thread.sleep(1000);
                }
            });
        }
        //主线程休眠6秒关闭线程池
        try {
            Thread.sleep(6000);
        }catch (InterruptedException e){
            throw  new RuntimeException(e);
        }
//        pool.shutdown();
        pool.shutdownNow();
        if (pool.isShutdown()) {
            System.out.println("关闭了线程池");
        }
    }
}
